﻿using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using MaterialDesignColors;
using MaterialDesignThemes.Wpf;
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using ZhuXingFamilys.ModelInformation.Entity;
using ZhuXingFamilys.ModelInformation.Entity.Engineering;
using DataGridTextColumn = System.Windows.Controls.DataGridTextColumn;
using Floor = Autodesk.Revit.DB.Floor;
using Parameter = Autodesk.Revit.DB.Parameter;
using TabItem = System.Windows.Controls.TabItem;


namespace ZhuXingFamilys.ModelInformation
{
    /// <summary>
    /// BuildingInfo.xaml 的交互逻辑
    /// </summary>
    public partial class BuildingInfo : System.Windows.Window
    {
        private Document doc;
        public BuildingInfo(Document linkDoc)
        {
            this.doc = linkDoc;
            //ui库使用
            ColorZoneAssist.SetMode(new System.Windows.Controls.GroupBox(), ColorZoneMode.Light);
            Hue hue = new Hue("name", System.Windows.Media.Color.FromArgb(1, 2, 3, 4), System.Windows.Media.Color.FromArgb(1, 5, 6, 7));
            InitializeComponent();
            this.SizeChanged += BuildingInfo_SizeChanged;
        }

        // 窗口尺寸变化
        private void BuildingInfo_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
            {
                double x1 = SystemParameters.PrimaryScreenWidth; //得到屏幕整体宽度
                double y1 = SystemParameters.PrimaryScreenHeight; //得到屏幕整体高度
                // 土建信息布局宽高
                this.ScrollViewer_engineeringInfo.MaxWidth = x1 - 281;
                this.ScrollViewer_engineeringInfo.MaxHeight = y1 - 70;
                // 机电信息布局宽高
                this.ScrollViewer_electromechanicalInfo.MaxWidth = x1 - 281;
                this.ScrollViewer_electromechanicalInfo.MaxHeight = y1 - 70;

            }
            else
            {
                // 土建信息布局宽高
                this.ScrollViewer_engineeringInfo.MaxWidth = this.Width - 266;
                this.ScrollViewer_engineeringInfo.MaxHeight = this.Height - 40;
                // 机电信息布局宽高
                this.ScrollViewer_electromechanicalInfo.MaxWidth = this.Width - 266;
                this.ScrollViewer_electromechanicalInfo.MaxHeight = this.Height - 40;
            }
        }

        // 窗口加载完成
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ProjectInfo linkProjectInfo = doc.ProjectInformation;
            // 标题
            Title = string.IsNullOrEmpty(linkProjectInfo.BuildingName) ? "单体信息" : linkProjectInfo.BuildingName;

            // 单体信息
            getBuildingInfo();
            // 楼层列表
            floorsList.ItemsSource = getFloorInfo();
            // 空间信息
            spaceInfoViewList.ItemsSource = getRoomInfo();
            // 功能分区信息
            partitionInfoViewList.ItemsSource = getPartitionInfo();
            // 土建分类列表
            engineeringInfoViewList.ItemsSource = getCivilEngineeringInfo();
            // 机电分类列表
            electromechanicalList.ItemsSource = getElectromechanicalInfo();
            // 小市政分类列表
            // municipalList.ItemsSource = getMunicipalInfo();
        }

        // 导航菜单选项切换
        private void MenuTabControl_OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            TabItem tabItem = e.Source as TabItem;
            if (tabItem != null && "土建信息".Equals(tabItem.Header.ToString()))
            {
                engineeringInfoViewList.SelectedIndex = 0;
            }

            if (tabItem != null && "机电信息".Equals(tabItem.Header.ToString()))
            {
                electromechanicalList.SelectedIndex = 0;
            }
        }

        // 楼层切换
        private void floorsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var floorID = floorsList.SelectedValue;
            var floors = getFloorInfo();
            foreach (var floor in floors)
            {
                if (floorID.Equals(floor.id))
                {
                    floorsInfoView.DataContext = floor;
                }
            }
        }
        // 土建分类切换
        private void engineeringInfoViewList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            engineeringInfoView.ItemsSource = null;
            engineeringInfoView.Columns.Clear();
            var selectedValue = engineeringInfoViewList.SelectedValue.ToString();
            if ("阳台".Equals(selectedValue))
            {
                // 生成表格
                generateTable<balcony>(engineeringInfoView);
                // 获取信息
                engineeringInfoView.ItemsSource = getBalconyInfo();
            }
            if ("板".Equals(selectedValue))
            {
                generateTable<slabs>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getSlabsInfo();
            }
            if ("墙".Equals(selectedValue))
            {
                generateTable<walls>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getWallsInfo();
            }
            if ("梁".Equals(selectedValue))
            {
                generateTable<beam>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getBeamssInfo();
            }
            if ("柱".Equals(selectedValue))
            {
                generateTable<column>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getColumnsInfo();
            }
            if ("栏杆/栏板".Equals(selectedValue))
            {
                generateTable<railing>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getRailingsInfo();
            }
            if ("雨棚".Equals(selectedValue))
            {
                generateTable<floors>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getFloorsInfo();
            }
            if ("雨棚".Equals(selectedValue))
            {
                generateTable<genericmodel>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getGenericModelInfo();
            }
            if ("楼梯".Equals(selectedValue))
            {
                generateTable<stairs>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getStairsInfo();
            }
            if ("门".Equals(selectedValue))
            {
                generateTable<door>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getDoorsInfo();
            }
            if ("窗".Equals(selectedValue))
            {
                generateTable<window>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getWindowInfo();
            }
            if ("坡屋顶".Equals(selectedValue) || "平屋顶".Equals(selectedValue))
            {
                generateTable<roofs>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getRoofsInfo(selectedValue);
            }
            if ("其他构件".Equals(selectedValue))
            {
                generateTable<Other_Components>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getOther_Components();
            }
            if ("特殊功能构件".Equals(selectedValue))
            {
                generateTable<Special_work_member>(engineeringInfoView);
                engineeringInfoView.ItemsSource = getSpecial_work_member();
            }
        }
        // 机电分类切换
        private void electromechanicalList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            electromechanicalInfoView.ItemsSource = null;
            electromechanicalInfoView.Columns.Clear();
            var selectedValue = electromechanicalList.SelectedValue.ToString();
            if ("管线".Equals(selectedValue))
            {
                generateTable<pipeline>(electromechanicalInfoView);
                electromechanicalInfoView.ItemsSource = getPipesInfo();
            }
            if ("连接件及末端设备表".Equals(selectedValue))
            {
                generateTable<connector>(electromechanicalInfoView);
                electromechanicalInfoView.ItemsSource = getConnectorInfo();
            }
            if ("水/电源".Equals(selectedValue))
            {
                generateTable<water>(electromechanicalInfoView);
                electromechanicalInfoView.ItemsSource = getwater();
            }
            if ("特殊设备设施".Equals(selectedValue))
            {
                generateTable<specialEquipment>(electromechanicalInfoView);
                // electromechanicalInfoView.ItemsSource = getPipesInfo();
            }
        }



        // 数据表格添加行号
        private void ExcelDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = (e.Row.GetIndex() + 1).ToString();
        }
        // ScrollViewer鼠标滚动
        private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            ScrollViewer viewer = scrollview1;
            if (viewer == null)
                return;
            double num = Math.Abs((int)(e.Delta / 2));
            double offset = 0.0;
            if (e.Delta > 0)
            {
                offset = Math.Max((double)0.0, (double)(viewer.VerticalOffset - num));
            }
            else
            {
                offset = Math.Min(viewer.ScrollableHeight, viewer.VerticalOffset + num);
            }
            if (offset != viewer.VerticalOffset)
            {
                viewer.ScrollToVerticalOffset(offset);
                e.Handled = true;
            }
        }
        // 根据实体类生成表格
        private void generateTable<T>(DataGrid dataGrid)
        {
            var columns = dataGrid.Columns;
            columns.Clear();
            // 序号列
            DataGridTextColumn xuhao = new DataGridTextColumn();
            xuhao.Header = "序号";
            xuhao.Binding = new System.Windows.Data.Binding()
            {
                Path = new PropertyPath("Header"),
                RelativeSource = new RelativeSource()
                {
                    AncestorType = typeof(DataGridRow)
                }
            };
            columns.Add(xuhao);

            // 反射实体类新建表格字段和绑定关系
            PropertyInfo[] peroperties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo peroperty in peroperties)
            {
                if (peroperty.Name.Equals("Id")) continue;
                object[] objs = peroperty.GetCustomAttributes(typeof(DescriptionAttribute), true);
                if (objs.Length > 0)
                {
                    // MessageBox.Show(peroperty.Name + ((DescriptionAttribute)objs[0]).Description);
                    DataGridTextColumn dgtc = new DataGridTextColumn()
                    {
                        Header = ((DescriptionAttribute)objs[0]).Description,
                        Binding = new System.Windows.Data.Binding()
                        {
                            Path = new PropertyPath(peroperty.Name)
                        }
                    };
                    columns.Add(dgtc);
                }

            }
        }

        #region 模型信息获取
        // 获取建筑单体信息
        private void getBuildingInfo()
        {
            ProjectInfo proj = doc.ProjectInformation;
            ParameterSet projParameters = proj.Parameters;
            var children = BuildingInfoWP.Children;

            foreach (Autodesk.Revit.DB.Parameter projParameter in projParameters)
            {
                foreach (var child in children)
                {
                    if (child is System.Windows.Controls.TextBox)
                    {
                        var tb = child as System.Windows.Controls.TextBox;
                        if (projParameter.Definition.Name.Equals(tb.Name))
                        {
                            tb.Text = projParameter.AsString();

                            string selectedText = projParameter.AsValueString();
                            if (selectedText == null)
                            {
                                continue;
                            }
                            else
                            {
                                tb.SelectedText = selectedText;
                            }
                        }
                    }
                }
            }
        }
        // 获取楼层信息
        private List<floorInfo> getFloorInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Levels).OfClass(typeof(Level));

            List<floorInfo> floorInfos = new List<floorInfo>();
            foreach (Element elem in collector.ToElements())
            {
                Level level = elem as Level;
                if (level == null) continue;
                floorInfo floor = new floorInfo();

                floor.id = elem.Id.ToString(); // ID
                floor.floor_name = elem.Name; // 楼层名称       
                                              //Parameter type = level.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM);
                                              //if (type != null)
                                              //    floor.floor_type = type.AsValueString(); // 楼层类型




                // 获取当前楼层下的房间信息
                FilteredElementCollector roomCollector = new FilteredElementCollector(doc);
                roomCollector.OfCategory(BuiltInCategory.OST_Rooms);
                roomCollector.WherePasses(new ElementLevelFilter(elem.Id));

                List<RoomInfo> roomInfos = new List<RoomInfo>();
                foreach (var room in roomCollector)
                {
                    Room r = room as Room;
                    if (r != null)
                    {
                        string area = GetRoomAreaAsString(r);
                        RoomInfo roomInfo = new RoomInfo(r.Name, area);
                        roomInfos.Add(roomInfo);
                    }
                }

                floor.RoomInfos = roomInfos;


                if (elem.LookupParameter("楼层类型") != null)
                    floor.floor_type = elem.LookupParameter("楼层类型").AsString();
                if (elem.LookupParameter("楼层编号") != null)
                    floor.floor_code = elem.LookupParameter("楼层编号").AsString();
                if (elem.LookupParameter("结构层高") != null)
                    floor.structural_height = elem.LookupParameter("结构层高").AsString();
                if (elem.LookupParameter("立面") != null)
                    floor.base_elevation = elem.LookupParameter("立面").AsValueString();
                if (elem.LookupParameter("主功能类别") != null)
                    floor.main_function_category = elem.LookupParameter("主功能类别").AsString();
                if (elem.LookupParameter("子功能类别") != null)
                    floor.sub_function_category = elem.LookupParameter("子功能类别").AsString();
                if (elem.LookupParameter("是否是避难层") != null)
                    floor.is_refuge_floor = elem.LookupParameter("是否是避难层").AsValueString();
                if (elem.LookupParameter("避难层防烟措施描述") != null)
                    floor.measures_description = elem.LookupParameter("避难层防烟措施描述").AsString();
                floorInfos.Add(floor);

            }
            return floorInfos;
        }
        // 获取空间信息
        private List<spaceInfo> getRoomInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Rooms);
            List<spaceInfo> spaceInfos = new List<spaceInfo>();
            foreach (Element elem in collector.ToElements())
            {
                Room room = elem as Room;
                if (room == null) continue;
                spaceInfo space = new spaceInfo();

                space.id = elem.Id.ToString(); // ID
                Autodesk.Revit.DB.Parameter roomNumber = room.get_Parameter(BuiltInParameter.ROOM_NUMBER);
                if (roomNumber != null)
                    space.space_code = roomNumber.AsString(); // 区域编号
                //if (room.LookupParameter("区域编号") != null)
                //    space.space_code = elem.LookupParameter("区域编号").AsString();
                if (room.LookupParameter("区域标记") != null)
                    space.space_label = elem.LookupParameter("区域标记").AsString();
                if (room.LookupParameter("主功能类别") != null)
                    space.main_function_type = elem.LookupParameter("主功能类别").AsString();
                if (room.LookupParameter("子功能类别") != null)
                    space.sub_function_type = elem.LookupParameter("子功能类别").AsString();
                if (room.LookupParameter("房间功能") != null)
                    space.room_function = elem.LookupParameter("房间功能").AsString();
                if (room.LookupParameter("是否为无障碍设计") != null)
                    space.accessible_flag = elem.LookupParameter("是否为无障碍设计").AsValueString();
                if (room.LookupParameter("结构层高") != null)
                    space.structural_height = elem.LookupParameter("结构层高").AsString();
                if (room.LookupParameter("区域类别") != null)
                    space.space_type = elem.LookupParameter("区域类别").AsString();
                if (room.LookupParameter("区域轮廓线") != null)
                    space.space_outline_line = elem.LookupParameter("区域轮廓线").AsString();
                Autodesk.Revit.DB.Parameter RoomAREA = room.get_Parameter(BuiltInParameter.ROOM_AREA);
                if (RoomAREA != null)
                    space.building_area = (decimal)Math.Round(UnitUtils.ConvertFromInternalUnits(RoomAREA.AsDouble(), RoomAREA.DisplayUnitType), 3); // 面积
                //if (room.LookupParameter("建筑面积") != null)
                //    space.building_area = elem.LookupParameter("建筑面积").AsString();
                if (room.LookupParameter("计容面积") != null)
                    space.capacity_area = (decimal)Math.Round(UnitUtils.ConvertFromInternalUnits(elem.LookupParameter("计容面积").AsDouble(), RoomAREA.DisplayUnitType), 3);
                if (room.LookupParameter("计容系数") != null)
                    space.capacity = elem.LookupParameter("计容系数").AsValueString();
                if (room.LookupParameter("计算系数") != null)
                    space.calculation = elem.LookupParameter("计算系数").AsValueString();
                if (room.LookupParameter("防淹措施") != null)
                    space.flood_prevention_measures = elem.LookupParameter("防淹措施").AsString();
                if (room.LookupParameter("空间区域耐火等级") != null)
                    space.fire_resistance_level = elem.LookupParameter("空间区域耐火等级").AsString();

                spaceInfos.Add(space);
            }
            return spaceInfos;
        }
        // 获取分区信息
        private List<partitionInfo> getPartitionInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Areas);
            List<partitionInfo> partitionInfos = new List<partitionInfo>();
            foreach (Element elem in collector.ToElements())
            {
                Area area = elem as Area;
                if (area == null) continue;
                partitionInfo info = new partitionInfo();

                info.id = elem.Id.ToString();
                Autodesk.Revit.DB.Parameter roomNumber = area.get_Parameter(BuiltInParameter.ROOM_NUMBER);
                if (roomNumber != null)
                    info.partition_code = roomNumber.AsString();
                if (area.LookupParameter("功能分区类别") != null)
                    info.partition_type = elem.LookupParameter("功能分区类别").AsString();
                if (area.LookupParameter("功能说明") != null)
                    info.partition_description = elem.LookupParameter("功能说明").AsString();
                if (area.LookupParameter("人防分区类别") != null)
                    info.defense_zoning_type = elem.LookupParameter("人防分区类别").AsString();
                if (area.LookupParameter("人防工程类别") != null)
                    info.defense_project_type = elem.LookupParameter("人防工程类别").AsString();
                if (area.LookupParameter("人防工程子分类") != null)
                    info.defense_project_sun_type = elem.LookupParameter("人防工程子分类").AsString();
                if (area.LookupParameter("人防工程组成") != null)
                    info.defense_project_from = elem.LookupParameter("人防工程组成").AsString();
                if (area.LookupParameter("所属防护单元名称") != null)
                    info.name_of_protection_unit = elem.LookupParameter("所属防护单元名称").AsString();
                if (area.LookupParameter("人防抗力等级") != null)
                    info.defense_resistance_level = elem.LookupParameter("人防抗力等级").AsString();
                if (area.LookupParameter("人防工程掩蔽人数") != null)
                    info.defense_cover_number = elem.LookupParameter("人防工程掩蔽人数").AsValueString();
                if (area.LookupParameter("人防工程掩蔽面积") != null)
                    info.defense_cover_area = elem.LookupParameter("人防工程掩蔽面积").AsValueString();
                if (area.LookupParameter("平时功能") != null)
                    info.normal_functions = elem.LookupParameter("平时功能").AsString();
                if (area.LookupParameter("区域轮廓线") != null)
                    info.area_contour_line = elem.LookupParameter("区域轮廓线").AsString();

                partitionInfos.Add(info);
            }
            return partitionInfos;
        }
        // 土建类型列表
        private List<string> getCivilEngineeringInfo()
        {
            List<string> sList = new List<string>()
            {
                "阳台","板","墙","梁","柱","栏杆/栏板","雨棚","楼梯","门","窗","坡屋顶","平屋顶","其他构件","特殊功能构件"
            };

            return sList;
        }
        // 获取阳台信息
        private List<balcony> getBalconyInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Rooms);
            List<balcony> balconies = new List<balcony>();

            foreach (Element elem in collector.ToElements())
            {
                Room room = elem as Room;
                if (room == null) continue;
                // 阳台：房间区域类型为‘阳台’
                Autodesk.Revit.DB.Parameter parameter = room.LookupParameter("区域类别");
                if (parameter != null && "阳台".Equals(parameter.AsString()))
                {
                    balcony b = new balcony();
                    b.Id = elem.Id.ToString();
                    if (room.LookupParameter("是否为封闭阳台") != null)
                        b.is_closed_balcony = elem.LookupParameter("是否为封闭阳台").AsValueString();
                    if (room.LookupParameter("是否为室外构件") != null)
                        b.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                    if (room.LookupParameter("面积") != null)
                        b.area = elem.LookupParameter("面积").AsString();
                    if (room.LookupParameter("结构层高") != null)
                        b.level = elem.LookupParameter("结构层高").AsString();
                    if (room.LookupParameter("不可回收构件") != null)
                        b.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();

                    balconies.Add(b);
                }

            }
            return balconies;
        }

        // 获取板信息
        private List<slabs> getSlabsInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Floors).OfClass(typeof(Floor));
            List<slabs> balconies = new List<slabs>();
            foreach (Element elem in collector.ToElements())
            {
                Floor floor = elem as Floor;
                if (floor == null) continue;
                slabs s = new slabs();
                s.Id = elem.Id.ToString();
                balconies.Add(s);
                Autodesk.Revit.DB.Parameter thickness = elem.get_Parameter(BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM); // 厚度
                if (thickness != null)
                    s.thickness = Math.Round(UnitUtils.ConvertFromInternalUnits(thickness.AsDouble(), thickness.DisplayUnitType), 3);
                if (floor.LookupParameter("不可回收构件") != null)
                    s.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (floor.LookupParameter("是否为室外构件") != null)
                    s.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (floor.LookupParameter("强度等级") != null)
                    s.strength_grade = elem.LookupParameter("强度等级").AsString();
                if (floor.LookupParameter("实测混凝土强度等级") != null)
                    s.measured_concrete_strength_grade = elem.LookupParameter("实测混凝土强度等级").AsString();
            }
            return balconies;
        }

        // 获取墙信息
        private List<walls> getWallsInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(Wall));
            List<walls> wallsList = new List<walls>();
            foreach (Element elem in collector.ToElements())
            {
                Wall wall = elem as Wall;
                if (wall == null) continue;
                walls w = new walls();
                w.Id = elem.Id.ToString();
                if (wall.LookupParameter("是否为室外构件") != null)
                    w.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (wall.LookupParameter("是否是防火墙") != null)
                    w.is_firewall = elem.LookupParameter("是否是防火墙").AsValueString();
                if (wall.LookupParameter("不可回收构件") != null)
                    w.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (wall.LookupParameter("强度等级") != null)
                    w.strength_grade = elem.LookupParameter("强度等级").AsString();
                if (wall.LookupParameter("实测混凝土强度等级") != null)
                    w.measured_concrete_strength_grade = elem.LookupParameter("实测混凝土强度等级").AsString();
                if (wall.LookupParameter("保温材料耐火极限") != null)
                    w.fire_resistance_limit = elem.LookupParameter("保温材料耐火极限").AsString();
                if (wall.LookupParameter("燃烧性能等级") != null)
                    w.combustion_performance_level = elem.LookupParameter("燃烧性能等级").AsString();
                if (wall.LookupParameter("实测厚度") != null)
                    w.measured_thickness = elem.LookupParameter("实测厚度").AsValueString();
                if (wall.LookupParameter("高度") != null)
                    w.height = elem.LookupParameter("高度").AsValueString();
                if (wall.LookupParameter("厚度") != null)
                    w.thickness = elem.LookupParameter("厚度").AsValueString();
                if (wall.LookupParameter("起点坐标X") != null)
                    w.startPointX = elem.LookupParameter("起点坐标X").AsString();
                if (wall.LookupParameter("起点坐标Y") != null)
                    w.startPointY = elem.LookupParameter("起点坐标Y").AsString();
                if (wall.LookupParameter("起点坐标Z") != null)
                    w.startPointZ = elem.LookupParameter("起点坐标Z").AsString();
                if (wall.LookupParameter("终点坐标X") != null)
                    w.endPointX = elem.LookupParameter("终点坐标X").AsString();
                if (wall.LookupParameter("终点坐标Y") != null)
                    w.endPointY = elem.LookupParameter("终点坐标Y").AsString();
                if (wall.LookupParameter("终点坐标Z") != null)
                    w.endPointZ = elem.LookupParameter("终点坐标Z").AsString();

                wallsList.Add(w);
            }
            return wallsList;
        }
        // 获取梁信息
        private List<beam> getBeamssInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_StructuralFraming).OfClass(typeof(FamilyInstance));
            List<beam> beams = new List<beam>();
            foreach (Element elem in collector.ToElements())
            {
                beam b = new beam();
                b.Id = elem.Id.ToString();

                if (elem.LookupParameter("底标高") != null)
                    b.base_elevation = elem.LookupParameter("底标高").AsValueString();
                if (elem.LookupParameter("截面最大高度") != null)
                    b.maximum_height_section = elem.LookupParameter("截面最大高度").AsValueString();
                if (elem.LookupParameter("截面最大宽度") != null)
                    b.maximum_width_section = elem.LookupParameter("截面最大宽度").AsValueString();
                if (elem.LookupParameter("强度等级") != null)
                    b.strength_grade = elem.LookupParameter("强度等级").AsString();
                if (elem.LookupParameter("实测混凝土强度等级") != null)
                    b.measured_concrete_strength_grade = elem.LookupParameter("实测混凝土强度等级").AsString();
                if (elem.LookupParameter("起点坐标X") != null)
                    b.startPointX = elem.LookupParameter("起点坐标X").AsString();
                if (elem.LookupParameter("起点坐标Y") != null)
                    b.startPointY = elem.LookupParameter("起点坐标Y").AsString();
                if (elem.LookupParameter("起点坐标Z") != null)
                    b.startPointZ = elem.LookupParameter("起点坐标Z").AsString();
                if (elem.LookupParameter("终点坐标X") != null)
                    b.endPointX = elem.LookupParameter("终点坐标X").AsString();
                if (elem.LookupParameter("终点坐标Y") != null)
                    b.endPointY = elem.LookupParameter("终点坐标Y").AsString();
                if (elem.LookupParameter("终点坐标Z") != null)
                    b.endPointZ = elem.LookupParameter("终点坐标Z").AsString();

                if (elem.LookupParameter("不可回收构件") != null)
                    b.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    b.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();

                beams.Add(b);
            }
            return beams;
        }

        // 获取柱信息
        private List<column> getColumnsInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Columns).OfClass(typeof(FamilyInstance));
            List<column> columns = new List<column>();
            foreach (Element elem in collector.ToElements())
            {
                column column = new column();
                column.Id = elem.Id.ToString();
                if (elem.LookupParameter("截面最大宽度") != null)
                    column.maximum_width_section = elem.LookupParameter("截面最大宽度").AsValueString();
                if (elem.LookupParameter("截面最大高度") != null)
                    column.maximum_height_section = elem.LookupParameter("截面最大高度").AsValueString();
                if (elem.LookupParameter("强度等级") != null)
                    column.strength_grade = elem.LookupParameter("强度等级").AsString();
                if (elem.LookupParameter("实测混凝土强度等级") != null)
                    column.measured_concrete_strength_grade = elem.LookupParameter("实测混凝土强度等级").AsString();
                if (elem.LookupParameter("起点坐标X") != null)
                    column.startPointX = elem.LookupParameter("起点坐标X").AsString();
                if (elem.LookupParameter("起点坐标Y") != null)
                    column.startPointY = elem.LookupParameter("起点坐标Y").AsString();
                if (elem.LookupParameter("起点坐标Z") != null)
                    column.startPointZ = elem.LookupParameter("起点坐标Z").AsString();
                if (elem.LookupParameter("终点坐标X") != null)
                    column.endPointX = elem.LookupParameter("终点坐标X").AsString();
                if (elem.LookupParameter("终点坐标Y") != null)
                    column.endPointY = elem.LookupParameter("终点坐标Y").AsString();
                if (elem.LookupParameter("终点坐标Z") != null)
                    column.endPointZ = elem.LookupParameter("终点坐标Z").AsString();
                if (elem.LookupParameter("不可回收构件") != null)
                    column.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    column.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();

                columns.Add(column);
            }

            return columns;
        }
        // 栏杆信息
        private List<railing> getRailingsInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_StairsRailing).OfClass(typeof(Railing));
            List<railing> railings = new List<railing>();
            foreach (Element elem in collector.ToElements())
            {
                railing railing = new railing();
                railing.Id = elem.Id.ToString();
                if (elem.LookupParameter("不可回收构件") != null)
                    railing.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    railing.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();

                railings.Add(railing);
            }
            return railings;
        }
        // 雨棚信息
        // OST_Floors
        private List<floors> getFloorsInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Floors).OfClass(typeof(Floor));
            List<floors> floors = new List<floors>();
            foreach (Element elem in collector.ToElements())
            {
                floors floor = new floors();
                floor.Id = elem.Id.ToString();
                if (elem.LookupParameter("不可回收构件") != null)
                    floor.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    floor.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();

                floors.Add(floor);
            }
            return floors;
        }
        // 常规雨棚信息
        // OST_GenericModel
        private List<genericmodel> getGenericModelInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_GenericModel).OfClass(typeof(FamilyInstance));
            List<genericmodel> genericmodels = new List<genericmodel>();
            foreach (Element elem in collector.ToElements())
            {
                genericmodel genericmodel = new genericmodel();
                genericmodel.Id = elem.Id.ToString();
                if (elem.LookupParameter("不可回收构件") != null)
                    genericmodel.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    genericmodel.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();

                genericmodels.Add(genericmodel);
            }
            return genericmodels;
        }
        // 楼梯信息
        private List<stairs> getStairsInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Stairs).OfClass(typeof(Stairs));
            List<stairs> ss = new List<stairs>();
            foreach (Element elem in collector.ToElements())
            {
                stairs stairs = new stairs();
                stairs.Id = elem.Id.ToString();
                if (elem.LookupParameter("不可回收构件") != null)
                    stairs.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    stairs.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("强度等级") != null)
                    stairs.strength_grade = elem.LookupParameter("强度等级").AsString();
                if (elem.LookupParameter("实测混凝土强度等级") != null)
                    stairs.measured_concrete_strength_grade = elem.LookupParameter("实测混凝土强度等级").AsString();

                ss.Add(stairs);
            }
            return ss;
        }
        // 门信息
        private List<door> getDoorsInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Doors).OfClass(typeof(FamilyInstance));
            List<door> doors = new List<door>();
            foreach (Element elem in collector.ToElements())
            {
                door door = new door();
                door.Id = elem.Id.ToString();
                if (elem.LookupParameter("不可回收构件") != null)
                    door.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    door.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                Autodesk.Revit.DB.Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM);
                if (eleType != null)
                {
                    door.type = eleType.AsValueString();
                }
                //if (elem.LookupParameter("门类型") != null)
                //    door.type = elem.LookupParameter("门类型").AsString();
                if (elem.LookupParameter("规格型号") != null)
                    door.specifications = elem.LookupParameter("规格型号").AsString();

                doors.Add(door);
            }
            return doors;
        }
        // 窗信息
        private List<window> getWindowInfo()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Windows).OfClass(typeof(FamilyInstance));
            List<window> windows = new List<window>();
            foreach (Element elem in collector.ToElements())
            {
                window window = new window();
                window.Id = elem.Id.ToString();

                if (elem.LookupParameter("是否为室外构件") != null)
                    window.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("不可回收构件") != null)
                    window.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (elem.LookupParameter("是否为消防救援窗") != null)
                    window.is_fire_fighting = elem.LookupParameter("是否为消防救援窗").AsValueString();
                Autodesk.Revit.DB.Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM);
                if (eleType != null)
                {
                    window.type = eleType.AsValueString();
                }
                windows.Add(window);
            }
            return windows;
        }
        // 屋顶
        private List<roofs> getRoofsInfo(string name)
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Roofs);
            if ("坡屋顶".Equals(name))
            {
                collector.OfClass(typeof(FootPrintRoof));
            }
            else if ("平屋顶".Equals(name))
            {
                collector.OfClass(typeof(FamilyInstance));
            }
            else
            {
                return null;
            }

            List<roofs> roofsList = new List<roofs>();
            foreach (Element elem in collector.ToElements())
            {
                roofs roofs = new roofs();
                roofs.Id = elem.Id.ToString();
                if (elem.LookupParameter("不可回收构件") != null)
                    roofs.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    roofs.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("强度等级") != null)
                    roofs.strength_grade = elem.LookupParameter("强度等级").AsString();
                if (elem.LookupParameter("实测混凝土强度等级") != null)
                    roofs.measured_concrete_strength_grade = elem.LookupParameter("实测混凝土强度等级").AsString();
                if (elem.LookupParameter("保温材料耐火极限") != null)
                    roofs.fire_resistance_limit = elem.LookupParameter("保温材料耐火极限").AsString();

                roofsList.Add(roofs);
            }
            return roofsList;
        }

        // 其他构件
        private List<Other_Components> getOther_Components()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Windows).OfClass(typeof(FamilyInstance));

            List<Other_Components> Other_Components = new List<Other_Components>();

            return Other_Components;

        }

        // 特殊功能构件
        private List<Special_work_member> getSpecial_work_member()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Windows).OfClass(typeof(FamilyInstance));

            List<Special_work_member> Special_work_members = new List<Special_work_member>();

            return Special_work_members;

        }

        // 机电分类列表
        private List<string> getElectromechanicalInfo()
        {
            List<string> sList = new List<string>()
            {
                "管线","连接件及末端设备表","水/电源","特殊设备设施"
            };
            return sList;
        }

        // 管线信息
        private List<pipeline> getPipesInfo()
        {
            List<pipeline> pipelines = new List<pipeline>();
            // 管道
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_PipeCurves).OfClass(typeof(Pipe));
            foreach (Element elem in collector.ToElements())
            {
                pipeline pl = new pipeline();
                pl.Id = elem.Id.ToString();
                if (elem.LookupParameter("管线编号") != null)
                    pl.code = elem.LookupParameter("管线编号").AsString();
                pl.name = elem.Name;
                Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM);
                if (eleType != null)
                {
                    pl.type = eleType.AsValueString();
                }
                if (elem.LookupParameter("专业类别") != null)
                    pl.professional_type = elem.LookupParameter("专业类别").AsString();
                Parameter eleSysType = elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
                if (eleSysType != null)
                {
                    pl.system_type = eleSysType.AsValueString();
                }
                if (elem.LookupParameter("二级系统类型") != null)
                    pl.secondary_system_type = elem.LookupParameter("二级系统类型").AsString();
                if (elem.LookupParameter("敷设方式") != null)
                    pl.laying_type = elem.LookupParameter("敷设方式").AsString();
                if (elem.LookupParameter("进户高压电缆规格") != null)
                    pl.cable_specifications = elem.LookupParameter("进户高压电缆规格").AsString();
                if (elem.LookupParameter("中心线") != null)
                    pl.centerline = elem.LookupParameter("中心线").AsValueString();
                if (elem.LookupParameter("备注") != null)
                    pl.notes = elem.LookupParameter("备注").AsString();
                Parameter eleDIAMETER = elem.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
                if (eleDIAMETER != null)
                {
                    pl.pipe_diameter = eleDIAMETER.AsValueString();
                }
                Parameter eleMaterial = elem.get_Parameter(BuiltInParameter.RBS_PIPE_MATERIAL_PARAM);
                if (eleMaterial != null)
                {
                    pl.pipe_material = eleMaterial.AsValueString();
                }
                if (elem.LookupParameter("是否为室外构件") != null)
                    pl.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("不可回收构件") != null)
                    pl.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                Parameter specification = elem.get_Parameter(BuiltInParameter.RBS_PIPE_CLASS_PARAM);
                if (specification != null)
                {
                    pl.specifications = specification.AsValueString();
                }

                pipelines.Add(pl);
            }
            // 风管
            collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_DuctCurves).OfClass(typeof(Duct));
            foreach (Element elem in collector.ToElements())
            {
                pipeline pl = new pipeline();
                pl.Id = elem.Id.ToString();
                if (elem.LookupParameter("管线编号") != null)
                    pl.code = elem.LookupParameter("管线编号").AsString();
                pl.name = elem.Name;
                Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM);
                if (eleType != null)
                {
                    pl.type = eleType.AsValueString();
                }
                if (elem.LookupParameter("专业类别") != null)
                    pl.professional_type = elem.LookupParameter("专业类别").AsString();
                Parameter eleSysType = elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
                if (eleSysType != null)
                {
                    pl.system_type = eleSysType.AsValueString();
                }
                if (elem.LookupParameter("二级系统类型") != null)
                    pl.secondary_system_type = elem.LookupParameter("二级系统类型").AsString();
                if (elem.LookupParameter("敷设方式") != null)
                    pl.laying_type = elem.LookupParameter("敷设方式").AsString();
                if (elem.LookupParameter("进户高压电缆规格") != null)
                    pl.cable_specifications = elem.LookupParameter("进户高压电缆规格").AsString();
                if (elem.LookupParameter("中心线") != null)
                    pl.centerline = elem.LookupParameter("中心线").AsValueString();
                if (elem.LookupParameter("备注") != null)
                    pl.notes = elem.LookupParameter("备注").AsString();
                Parameter eleDIAMETER = elem.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
                if (eleDIAMETER != null)
                {
                    pl.pipe_diameter = eleDIAMETER.AsValueString();
                }
                Parameter eleMaterial = elem.get_Parameter(BuiltInParameter.RBS_PIPE_MATERIAL_PARAM);
                if (eleMaterial != null)
                {
                    pl.pipe_material = eleMaterial.AsValueString();
                }
                if (elem.LookupParameter("是否为室外构件") != null)
                    pl.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("不可回收构件") != null)
                    pl.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                Parameter specification = elem.get_Parameter(BuiltInParameter.RBS_PIPE_CLASS_PARAM);
                if (specification != null)
                {
                    pl.specifications = specification.AsValueString();
                }
                pipelines.Add(pl);
            }

            // 电缆桥架
            collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_CableTray).OfClass(typeof(CableTray));
            foreach (Element elem in collector.ToElements())
            {
                pipeline pl = new pipeline();
                pl.Id = elem.Id.ToString();
                if (elem.LookupParameter("管线编号") != null)
                    pl.code = elem.LookupParameter("管线编号").AsString();
                pl.name = elem.Name;
                Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM);
                if (eleType != null)
                {
                    pl.type = eleType.AsValueString();
                }
                if (elem.LookupParameter("专业类别") != null)
                    pl.professional_type = elem.LookupParameter("专业类别").AsString();
                Parameter eleSysType = elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
                if (eleSysType != null)
                {
                    pl.system_type = eleSysType.AsValueString();
                }
                if (elem.LookupParameter("二级系统类型") != null)
                    pl.secondary_system_type = elem.LookupParameter("二级系统类型").AsString();
                if (elem.LookupParameter("敷设方式") != null)
                    pl.laying_type = elem.LookupParameter("敷设方式").AsString();
                if (elem.LookupParameter("进户高压电缆规格") != null)
                    pl.cable_specifications = elem.LookupParameter("进户高压电缆规格").AsString();
                if (elem.LookupParameter("中心线") != null)
                    pl.centerline = elem.LookupParameter("中心线").AsValueString();
                if (elem.LookupParameter("备注") != null)
                    pl.notes = elem.LookupParameter("备注").AsString();
                Parameter eleDIAMETER = elem.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
                if (eleDIAMETER != null)
                {
                    pl.pipe_diameter = eleDIAMETER.AsValueString();
                }
                Parameter eleMaterial = elem.get_Parameter(BuiltInParameter.RBS_PIPE_MATERIAL_PARAM);
                if (eleMaterial != null)
                {
                    pl.pipe_material = eleMaterial.AsValueString();
                }
                if (elem.LookupParameter("是否为室外构件") != null)
                    pl.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("不可回收构件") != null)
                    pl.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                Parameter specification = elem.get_Parameter(BuiltInParameter.RBS_PIPE_CLASS_PARAM);
                if (specification != null)
                {
                    pl.specifications = specification.AsValueString();
                }
                pipelines.Add(pl);
            }

            return pipelines;
        }
        // 连接件及末端设备表
        private List<connector> getConnectorInfo()
        {
            List<connector> connectors = new List<connector>();
            // 管件
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_PipeFitting).OfClass(typeof(FamilyInstance));
            foreach (Element elem in collector.ToElements())
            {
                connector ctr = new connector();
                ctr.Id = elem.Id.ToString();
                if (elem.LookupParameter("管线编号") != null)
                    ctr.code = elem.LookupParameter("管线编号").AsString();
                ctr.name = elem.Name;
                Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM);
                if (eleType != null)
                {
                    ctr.type = eleType.AsValueString();
                }
                if (elem.LookupParameter("专业类别") != null)
                    ctr.professional_type = elem.LookupParameter("专业类别").AsString();
                Parameter eleSysType = elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
                if (eleSysType != null)
                {
                    ctr.system_type = eleSysType.AsValueString();
                }
                if (elem.LookupParameter("二级系统类型") != null)
                    ctr.secondary_system_type = elem.LookupParameter("二级系统类型").AsString();
                if (elem.LookupParameter("敷设方式") != null)
                    ctr.laying_type = elem.LookupParameter("敷设方式").AsString();
                if (elem.LookupParameter("管件及末端设备类型") != null)
                    ctr.end_equipment = elem.LookupParameter("管件及末端设备类型").AsString();
                if (elem.LookupParameter("备注") != null)
                    ctr.notes = elem.LookupParameter("备注").AsString();
                if (elem.LookupParameter("连接点") != null)
                    ctr.connect_point = elem.LookupParameter("连接点").AsString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    ctr.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("不可回收构件") != null)
                    ctr.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                Parameter specification = elem.get_Parameter(BuiltInParameter.RBS_PIPE_CLASS_PARAM);
                if (specification != null)
                {
                    ctr.specifications = specification.AsString();
                }

                if (elem.LookupParameter("规格") != null)
                    ctr.specifications = elem.LookupParameter("规格").AsString();

                if (elem.LookupParameter("实测长度") != null)
                    ctr.measured_length = elem.LookupParameter("实测长度").AsString();
                if (elem.LookupParameter("实测进水口到井盖的距离") != null)
                    ctr.water_inlet_to_manhole_cover = elem.LookupParameter("实测进水口到井盖的距离").AsValueString();
                if (elem.LookupParameter("实测底部距地面的距离") != null)
                    ctr.bottom_to_ground = elem.LookupParameter("实测底部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测顶部距地面的距离") != null)
                    ctr.top_to_ground = elem.LookupParameter("实测顶部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测安装角度") != null)
                    ctr.installation_angle = elem.LookupParameter("实测安装角度").AsString();
                connectors.Add(ctr);
            }

            // 风管管件
            collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_DuctFitting).OfClass(typeof(FamilyInstance));
            foreach (Element elem in collector.ToElements())
            {
                connector ctr = new connector();
                ctr.Id = elem.Id.ToString();
                if (elem.LookupParameter("管线编号") != null)
                    ctr.code = elem.LookupParameter("管线编号").AsString();
                ctr.name = elem.Name;
                Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM);
                if (eleType != null)
                {
                    ctr.type = eleType.AsValueString();
                }
                if (elem.LookupParameter("专业类别") != null)
                    ctr.professional_type = elem.LookupParameter("专业类别").AsString();
                Parameter eleSysType = elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
                if (eleSysType != null)
                {
                    ctr.system_type = eleSysType.AsString();
                }
                if (elem.LookupParameter("二级系统类型") != null)
                    ctr.secondary_system_type = elem.LookupParameter("二级系统类型").AsString();
                if (elem.LookupParameter("敷设方式") != null)
                    ctr.laying_type = elem.LookupParameter("敷设方式").AsString();
                if (elem.LookupParameter("管件及末端设备类型") != null)
                    ctr.end_equipment = elem.LookupParameter("管件及末端设备类型").AsString();
                if (elem.LookupParameter("备注") != null)
                    ctr.notes = elem.LookupParameter("备注").AsString();
                if (elem.LookupParameter("连接点") != null)
                    ctr.connect_point = elem.LookupParameter("连接点").AsString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    ctr.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("不可回收构件") != null)
                    ctr.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                Parameter specification = elem.get_Parameter(BuiltInParameter.RBS_PIPE_CLASS_PARAM);
                if (specification != null)
                {
                    ctr.specifications = specification.AsValueString();
                }
                if (elem.LookupParameter("实测长度") != null)
                    ctr.measured_length = elem.LookupParameter("实测长度").AsString();
                if (elem.LookupParameter("实测进水口到井盖的距离") != null)
                    ctr.water_inlet_to_manhole_cover = elem.LookupParameter("实测进水口到井盖的距离").AsValueString();
                if (elem.LookupParameter("实测底部距地面的距离") != null)
                    ctr.bottom_to_ground = elem.LookupParameter("实测底部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测顶部距地面的距离") != null)
                    ctr.top_to_ground = elem.LookupParameter("实测顶部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测安装角度") != null)
                    ctr.installation_angle = elem.LookupParameter("实测安装角度").AsString();
                connectors.Add(ctr);
            }

            // 机械设备
            collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_MechanicalEquipment).OfClass(typeof(FamilyInstance));
            foreach (Element elem in collector.ToElements())
            {
                connector ctr = new connector();
                ctr.Id = elem.Id.ToString();
                if (elem.LookupParameter("管线编号") != null)
                    ctr.code = elem.LookupParameter("管线编号").AsString();
                ctr.name = elem.Name;
                Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM);
                if (eleType != null)
                {
                    ctr.type = eleType.AsValueString();
                }
                if (elem.LookupParameter("专业类别") != null)
                    ctr.professional_type = elem.LookupParameter("专业类别").AsString();
                Parameter eleSysType = elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
                if (eleSysType != null)
                {
                    ctr.system_type = eleSysType.AsValueString();
                }
                if (elem.LookupParameter("二级系统类型") != null)
                    ctr.secondary_system_type = elem.LookupParameter("二级系统类型").AsString();
                if (elem.LookupParameter("敷设方式") != null)
                    ctr.laying_type = elem.LookupParameter("敷设方式").AsString();
                if (elem.LookupParameter("管件及末端设备类型") != null)
                    ctr.end_equipment = elem.LookupParameter("管件及末端设备类型").AsString();
                if (elem.LookupParameter("备注") != null)
                    ctr.notes = elem.LookupParameter("备注").AsString();
                if (elem.LookupParameter("连接点") != null)
                    ctr.connect_point = elem.LookupParameter("连接点").AsString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    ctr.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("不可回收构件") != null)
                    ctr.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                Parameter specification = elem.get_Parameter(BuiltInParameter.RBS_PIPE_CLASS_PARAM);
                if (specification != null)
                {
                    ctr.specifications = specification.AsString();
                }
                if (elem.LookupParameter("实测长度") != null)
                    ctr.measured_length = elem.LookupParameter("实测长度").AsString();
                if (elem.LookupParameter("实测进水口到井盖的距离") != null)
                    ctr.water_inlet_to_manhole_cover = elem.LookupParameter("实测进水口到井盖的距离").AsValueString();
                if (elem.LookupParameter("实测底部距地面的距离") != null)
                    ctr.bottom_to_ground = elem.LookupParameter("实测底部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测顶部距地面的距离") != null)
                    ctr.top_to_ground = elem.LookupParameter("实测顶部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测安装角度") != null)
                    ctr.installation_angle = elem.LookupParameter("实测安装角度").AsString();
                connectors.Add(ctr);
            }

            // 电缆桥架配件
            collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_CableTrayFitting).OfClass(typeof(FamilyInstance));
            foreach (Element elem in collector.ToElements())
            {
                connector ctr = new connector();
                ctr.Id = elem.Id.ToString();
                if (elem.LookupParameter("管线编号") != null)
                    ctr.code = elem.LookupParameter("管线编号").AsString();
                ctr.name = elem.Name;
                Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM);
                if (eleType != null)
                {
                    ctr.type = eleType.AsValueString();
                }
                if (elem.LookupParameter("专业类别") != null)
                    ctr.professional_type = elem.LookupParameter("专业类别").AsString();
                Parameter eleSysType = elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
                if (eleSysType != null)
                {
                    ctr.system_type = eleSysType.AsValueString();
                }
                if (elem.LookupParameter("二级系统类型") != null)
                    ctr.secondary_system_type = elem.LookupParameter("二级系统类型").AsString();
                if (elem.LookupParameter("敷设方式") != null)
                    ctr.laying_type = elem.LookupParameter("敷设方式").AsString();
                if (elem.LookupParameter("管件及末端设备类型") != null)
                    ctr.end_equipment = elem.LookupParameter("管件及末端设备类型").AsString();
                if (elem.LookupParameter("备注") != null)
                    ctr.notes = elem.LookupParameter("备注").AsString();
                if (elem.LookupParameter("连接点") != null)
                    ctr.connect_point = elem.LookupParameter("连接点").AsString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    ctr.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("不可回收构件") != null)
                    ctr.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                Parameter specification = elem.get_Parameter(BuiltInParameter.RBS_PIPE_CLASS_PARAM);
                if (specification != null)
                {
                    ctr.specifications = specification.AsString();
                }
                if (elem.LookupParameter("实测长度") != null)
                    ctr.measured_length = elem.LookupParameter("实测长度").AsString();
                if (elem.LookupParameter("实测进水口到井盖的距离") != null)
                    ctr.water_inlet_to_manhole_cover = elem.LookupParameter("实测进水口到井盖的距离").AsValueString();
                if (elem.LookupParameter("实测底部距地面的距离") != null)
                    ctr.bottom_to_ground = elem.LookupParameter("实测底部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测顶部距地面的距离") != null)
                    ctr.top_to_ground = elem.LookupParameter("实测顶部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测安装角度") != null)
                    ctr.installation_angle = elem.LookupParameter("实测安装角度").AsString();
                connectors.Add(ctr);
            }

            // 风道末端
            collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_DuctTerminal).OfClass(typeof(FamilyInstance));
            foreach (Element elem in collector.ToElements())
            {
                connector ctr = new connector();
                ctr.Id = elem.Id.ToString();
                if (elem.LookupParameter("管线编号") != null)
                    ctr.code = elem.LookupParameter("管线编号").AsString();
                ctr.name = elem.Name;
                Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM);
                if (eleType != null)
                {
                    ctr.type = eleType.AsValueString();
                }
                if (elem.LookupParameter("专业类别") != null)
                    ctr.professional_type = elem.LookupParameter("专业类别").AsString();
                Parameter eleSysType = elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
                if (eleSysType != null)
                {
                    ctr.system_type = eleSysType.AsValueString();
                }
                if (elem.LookupParameter("二级系统类型") != null)
                    ctr.secondary_system_type = elem.LookupParameter("二级系统类型").AsString();
                if (elem.LookupParameter("敷设方式") != null)
                    ctr.laying_type = elem.LookupParameter("敷设方式").AsString();
                if (elem.LookupParameter("管件及末端设备类型") != null)
                    ctr.end_equipment = elem.LookupParameter("管件及末端设备类型").AsString();
                if (elem.LookupParameter("备注") != null)
                    ctr.notes = elem.LookupParameter("备注").AsString();
                if (elem.LookupParameter("连接点") != null)
                    ctr.connect_point = elem.LookupParameter("连接点").AsString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    ctr.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("不可回收构件") != null)
                    ctr.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                Parameter specification = elem.get_Parameter(BuiltInParameter.RBS_PIPE_CLASS_PARAM);
                if (specification != null)
                {
                    ctr.specifications = specification.AsString();
                }
                if (elem.LookupParameter("实测长度") != null)
                    ctr.measured_length = elem.LookupParameter("实测长度").AsString();
                if (elem.LookupParameter("实测进水口到井盖的距离") != null)
                    ctr.water_inlet_to_manhole_cover = elem.LookupParameter("实测进水口到井盖的距离").AsValueString();
                if (elem.LookupParameter("实测底部距地面的距离") != null)
                    ctr.bottom_to_ground = elem.LookupParameter("实测底部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测顶部距地面的距离") != null)
                    ctr.top_to_ground = elem.LookupParameter("实测顶部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测安装角度") != null)
                    ctr.installation_angle = elem.LookupParameter("实测安装角度").AsString();
                connectors.Add(ctr);
            }

            // 专用设备
            collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_SpecialityEquipment).OfClass(typeof(FamilyInstance));
            foreach (Element elem in collector.ToElements())
            {
                connector ctr = new connector();
                ctr.Id = elem.Id.ToString();
                if (elem.LookupParameter("管线编号") != null)
                    ctr.code = elem.LookupParameter("管线编号").AsString();
                ctr.name = elem.Name;
                Parameter eleType = elem.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM);
                if (eleType != null)
                {
                    ctr.type = eleType.AsValueString();
                }
                if (elem.LookupParameter("专业类别") != null)
                    ctr.professional_type = elem.LookupParameter("专业类别").AsString();
                Parameter eleSysType = elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
                if (eleSysType != null)
                {
                    ctr.system_type = eleSysType.AsValueString();
                }
                if (elem.LookupParameter("二级系统类型") != null)
                    ctr.secondary_system_type = elem.LookupParameter("二级系统类型").AsString();
                if (elem.LookupParameter("敷设方式") != null)
                    ctr.laying_type = elem.LookupParameter("敷设方式").AsString();
                if (elem.LookupParameter("管件及末端设备类型") != null)
                    ctr.end_equipment = elem.LookupParameter("管件及末端设备类型").AsString();
                if (elem.LookupParameter("备注") != null)
                    ctr.notes = elem.LookupParameter("备注").AsString();
                if (elem.LookupParameter("连接点") != null)
                    ctr.connect_point = elem.LookupParameter("连接点").AsString();
                if (elem.LookupParameter("是否为室外构件") != null)
                    ctr.is_outdoor_components = elem.LookupParameter("是否为室外构件").AsValueString();
                if (elem.LookupParameter("不可回收构件") != null)
                    ctr.Non_recyclable = elem.LookupParameter("不可回收构件").AsValueString();
                Parameter specification = elem.get_Parameter(BuiltInParameter.RBS_PIPE_CLASS_PARAM);
                if (specification != null)
                {
                    ctr.specifications = specification.AsString();
                }

                if (elem.LookupParameter("规格") != null)
                    ctr.specifications = elem.LookupParameter("规格").AsString();

                if (elem.LookupParameter("实测长度") != null)
                    ctr.measured_length = elem.LookupParameter("实测长度").AsString();
                if (elem.LookupParameter("实测进水口到井盖的距离") != null)
                    ctr.water_inlet_to_manhole_cover = elem.LookupParameter("实测进水口到井盖的距离").AsValueString();
                if (elem.LookupParameter("实测底部距地面的距离") != null)
                    ctr.bottom_to_ground = elem.LookupParameter("实测底部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测顶部距地面的距离") != null)
                    ctr.top_to_ground = elem.LookupParameter("实测顶部距地面的距离").AsValueString();
                if (elem.LookupParameter("实测安装角度") != null)
                    ctr.installation_angle = elem.LookupParameter("实测安装角度").AsString();
                connectors.Add(ctr);
            }

            return connectors;
        }

        // 水/电源
        private List<water> getwater()
        {
            var collector = new FilteredElementCollector(doc);
            collector.OfCategory(BuiltInCategory.OST_Windows).OfClass(typeof(FamilyInstance));

            List<water> waters = new List<water>();

            return waters;

        }

        // 小市政分类列表
        //private List<string> getMunicipalInfo()
        //{
        //    List<string> sList = new List<string>()
        //    {
        //        "井","道路","出入口","停车位","室外场地","绿地","树木","场地地形","出入口构筑物","城市家具","IOT设备"
        //    };
        //    return sList;
        //}



        #endregion

        private void 建筑编号_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void MenuTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void 基点坐标X_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void 是否为标志性建筑_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void 子功能类别_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void GridSplitter_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
        {

        }

        private string GetRoomAreaAsString(Room room)
        {
            Parameter areaParameter = room.get_Parameter(BuiltInParameter.ROOM_AREA);
            return areaParameter != null ? areaParameter.AsValueString() : "";
        }


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // 遍历楼层信息，找到指定楼层的房间信息
            List<floorInfo> floorInfos = getFloorInfo();

            StringBuilder roomInfo = new StringBuilder();
            foreach (var floor in floorInfos)
            {
                roomInfo.AppendLine("楼层名称：" + floor.floor_name);
                foreach (var room in floor.RoomInfos)
                {
                    roomInfo.AppendLine("房间名称：" + room.RoomName + " 面积：" + room.Area);
                }
                roomInfo.AppendLine();
            }

            TaskDialog.Show("房间信息", roomInfo.ToString());


            //// 获取F1楼层的ElementId
            //FilteredElementCollector collector = new FilteredElementCollector(doc);
            //ElementId f1FloorId = null;
            //var levels = collector.OfCategory(BuiltInCategory.OST_Levels).ToElements();
            //foreach (var level in levels)
            //{
            //    if (level.Name == "F1")
            //    {
            //        f1FloorId = level.Id;
            //        break;
            //    }
            //}

            //// 遍历房间并筛选出属于F1楼层的房间
            //FilteredElementCollector roomCollector = new FilteredElementCollector(doc);
            //roomCollector.OfCategory(BuiltInCategory.OST_Rooms);
            //roomCollector.WherePasses(new ElementLevelFilter(f1FloorId));

            //// 输出房间信息
            //StringBuilder roomInfo = new StringBuilder();
            //foreach (var room in roomCollector)
            //{
            //    Room r = room as Room;
            //    if (r != null)
            //    {
            //        // 获取房间面积并进行处理

            //        string area = GetRoomAreaAsString(r);
            //        // 此处可以根据具体需求进行处理
            //        roomInfo.AppendLine("房间名称：" + r.Name + " 面积：" + area.ToString());
            //    }
            //}
            // 显示房间信息
            // TaskDialog.Show("房间信息", roomInfo.ToString());
        }

        private void concrete(object sender, RoutedEventArgs e)
        {
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            collector.OfClass(typeof(FamilyInstance));

            StringBuilder roomInfo = new StringBuilder();

            string aa = "";
            string bb = "";
            foreach (Element elem in collector.ToElements())
            {
                if (elem.LookupParameter("体积") != null)
                    bb = elem.LookupParameter("体积").AsValueString();
                if (elem.LookupParameter("族") != null)
                {
                    aa = elem.LookupParameter("族").AsValueString();

                    if (aa.Contains("混凝土"))
                        roomInfo.AppendLine("名称：" + aa + " 工程量：" + bb);

                    if (aa.Contains("钢材"))
                        roomInfo.AppendLine("名称：" + aa + " 工程量：" + bb);

                    if (aa.Contains("门"))
                        roomInfo.AppendLine("名称：" + aa + " 工程量：" + bb);

                    if (aa.Contains("窗"))
                        roomInfo.AppendLine("名称：" + aa + " 工程量：" + bb);
                }
            }
            TaskDialog.Show("信息", $"{roomInfo.ToString()}");




        }
    }
}

